# -*- coding:utf-8 -*-
"""
使用信号量解决创建用户时，密码明文保存的问题
"""
__author__ = "shu2015626"

#
# # from django.conf import settings
# from django.db.models.signals import post_save
# from django.dispatch import receiver
# from django.contrib.auth import get_user_model
#
# User = get_user_model()
#
#
# # @receiver(post_save, sender=settings.AUTH_USER_MODEL)
# @receiver(post_save, sender=User, dispatch_uid="user_post_save")
# def create_user(sender, instance=None, created=False, **kwargs):
#     """
#     通过信号量，解决密码明文的问题
#     https://docs.djangoproject.com/en/2.1/ref/signals/#django.db.models.signals.pre_save
#     # 搜索post_save，有用法
#     https://www.django-rest-framework.org/api-guide/authentication/
#
#     需要去apps.py中重载ready方法.
#
#     测试：通过前端api接口传递过来的明文密码，可以解决掉
#     但是直接在后台新增用户的时候，密码被修改了2遍（哈希了两边）。
#     还是重写serializers的create方法吧，逻辑上也比较好找
#     """
#     if created:
#         password = instance.password
#         instance.set_password(password)
#         instance.save()

